package com.yulongtian.offers.day202208.day20220823;

import java.util.Stack;

/**
 * @author YulongTian
 * @date 2022/8/23 - 12:53
 */
public class JianZhiOffer01 {
    public static void main(String[] args) {

    }
}

class CQueue {

    static Stack<Integer> stackLeft = new Stack<>();
    static Stack<Integer> stackRight = new Stack<>();


    public CQueue() {
        stackLeft.clear();
        stackRight.clear();
    }

    public void appendTail(int value) {
        if (stackRight.empty()) {
            stackLeft.push(value);
            return;
        }
        if (stackLeft.empty()) {
            while (!stackRight.empty()) {
                stackLeft.push(stackRight.pop());
            }
            stackLeft.push(value);
            return;
        }
        stackLeft.push(value);

    }

    public int deleteHead() {
        //一开始左栈不空
        if (!stackLeft.empty()) {
            //    左栈不为空
            while (!stackLeft.empty()) {
                stackRight.push(stackLeft.pop());
            }
            return stackRight.pop();
        }

        //然后右栈不空
        if (!stackRight.empty()) {
            int res = stackRight.pop();
            while (!stackRight.empty()) {
                stackLeft.push(stackRight.pop());
            }
            return res;
        }

        return -1;
    }
}

